#!/bin/bash
cmd=$( basename "$0" )
img="sophgo/tpuc_dev:v3.2"
dockerName="ljs-sophon-docker"

function usage() {
    echo "Usage: ${cmd} [-i | -n | -h]" 
    echo "      启动docker"
    echo "      -i: <docker_img>:<docker_tag>, 缺省: ${img}"
    echo "      -n: docker容器名称，缺省: ${dockerName}"
    echo "      -h: 输出此信息"
    exit 1
}

while getopts "i:n:h" arg
do
    case "${arg}" in 
        i)
            img="${OPTARG}"
            ;;
        n)
            dockerName="${OPTARG}"
            ;;
        *)
            usage
            ;;
    esac
done

echo "Run image ${img}..."

hostDir="${HOME}/docker_homes/sophon_home"
etcDir="${HOME}/sys/etc_sophgo"
# liujinsong on 161
user="1172"
group="502"
clientHome="/home/sophon"

# 先删除就得container
docker container rm -f ${dockerName} 2> /dev/null

echo run docker image ${img}

docker run \
    -u ${user}:${group}\
    -v ${etcDir}/group:/etc/group:ro \
    -v ${etcDir}/sudoers:/etc/sudoers:ro \
    -v ${etcDir}/passwd:/etc/passwd:ro \
    -v ${etcDir}/shadow:/etc/shadow:ro \
    -v ${HOMEA}/datasets:${clientHome}/datasets \
    -v ${hostDir}:${clientHome} \
    -v ${HOME}/bin:${clientHome}/bin \
    -v ${HOME}/tmp:${clientHome}/tmp \
    -v ${HOME}/exer:${clientHome}/exer \
    -v ${HOME}/download:${clientHome}/download \
    -v ${HOME}/work:${clientHome}/work \
    -v ${HOME}/sophon:${clientHome}/sophon \
    -w ${clientHome} \
    --name "${dockerName}" \
    -it \
    ${img}
